/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.ex;

import java.io.File;
import java.util.UUID;

/**
 * <p>Project: javase - Ex2
 * <p>Powered by webrx On 2021-12-06 09:10:50
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex2 {
    public static void main(String[] args) {
        String p = "d:/xxx/user/user_abc.jpg";
        System.out.println(p);
        //File.separator 是根据系统返回相关的符号 linux / windows \ \\
        String fc = File.separator;
        fc = p.indexOf(fc) == -1 ? "/" : fc;
        System.out.println(fc);
        String path = p.substring(0, p.lastIndexOf(fc)).concat(fc);
        System.out.println(path);
        String name = p.substring(p.lastIndexOf(fc) + 1);
        System.out.println(name);
        String ext = name.lastIndexOf(".") == -1 ? "" : name.substring(name.lastIndexOf(".") + 1);
        System.out.println(ext);
        UUID uuid = UUID.randomUUID();
        String newp = String.format("%s%s.%s", path, uuid, ext);
        System.out.println(newp);
    }
}
